import axios from 'axios';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
  account: string;
  password: string;
}

export interface LoginRes {
  id: number;
  role_ids: string;
  account: string;
  nickname: string;
  phone: string;
  email: string;
  avatar_id: string;
  introduce: string;
  login_number: number;
  login_last_ip: string;
  login_last_ip_region: string;
  login_last_time: string;
  is_super: number;
  is_disable: number;
  create_time: string;
  update_time: string;
  delete_time: string;
  token: string;
}

export function login(data: LoginData) {
  return axios.post<LoginRes>('/admin/system/user/login', data);
}

export function logout() {
  return axios.post<LoginRes>('/admin/system/user/logout');
}

export function getUserInfo() {
  return axios.get<UserState>('/admin/system/user/info');
}

export interface RegisterData {
  nickName: string;
  password: string;
  email: string;
  authCode: string;
  agreeProtocol: boolean;
}

export function register(data: RegisterData) {
  return axios.post<string>('/admin/system/user/register', data);
}

export interface ResetPasswordData {
  email: string;
  authCode: string;
  newPassword: string;
}

export function resetPassword(data: ResetPasswordData) {
  return axios.post<string>('/admin/system/user/reset', data);
}

export const uploadUserAvatarUrl = `${process.env.BASE_API}system/user/avatar`;
